package com.woniuxy.carlife.carlifeplatformweb.controller;


import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.Result;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.StatusCode;
import com.woniuxy.carlife.carlifeplatformweb.param.ManagerAccountLoginParam;
import com.woniuxy.carlife.carlifeplatformweb.param.ManagerAccountRegisterParam;
import com.woniuxy.carlife.carlifeplatformweb.service.ManagerAccountService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName: ManagerAccountController
 *@Description: 管理员账号表 前端控制器
 * @author: huangxinyan     
 * @date: 2021-04-05
 */

@RestController
@Slf4j
@Api(tags = "平台账号接口信息")//用于描述接口类的相关信息，作用于类上
@RequestMapping("/manager-account")
public class ManagerAccountController {

    @Resource
    private ManagerAccountService managerAccountService;

    /**
     * 功能描述〈管理员新增>
     * @author: huangxinyan
     * @param:  [ManagerAccountRegisterParam]
     * @return: massage
     * @Date 2021/4/7 11:15
     * @throws
     */

    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "管理员新增",notes = "<span style='color:red;'>用来管理员的接口</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 40009,message = "管理员新增成功",response = ManagerAccountRegisterParam.class),
            @ApiResponse(code=70023,message = "账号为空"),
            @ApiResponse(code=70029,message = "密码为空"),
            @ApiResponse(code=40010,message = "管理员新增失败")

    })

    @PostMapping("/FindManagerAccountAll")
    public Result setStoreRegister(@ModelAttribute @ApiParam ManagerAccountRegisterParam managerAccountRegisterParam) {
        log.info("管理员新增开始：参数：{}", managerAccountRegisterParam);
        if (managerAccountRegisterParam.getManagerAccountName()!=null){
            if (managerAccountRegisterParam.getManagerAccountPassword()!=null){
                //将前端传入注册信息集合传入数据层，获取返回值，返回为1 注册成功，2 注册失败
                Integer codess=managerAccountService.setManagerAccount(managerAccountRegisterParam);
                if(codess==0){
                    log.info("管理员新增结束：参数：{}",codess);
                    return new Result(true, StatusCode.REGISTRATION_SUCCESS,"管理员新增成功");
                }else {
                    return new Result(false, StatusCode.REGISTRATION_FAILED, "管理员新增失败");
                }
            }else {
                    return new Result(false, StatusCode.STORE_PASSWORD_EMPTY,"密码不能为空");
            }
        }else {
            return new Result(false, StatusCode.ACCOUNT_EMPTY,"账号不能为空");
        }
    }

    /**
     * 功能描述〈管理员登录〉
     * @author: huangxinyan
     * @param: ManagerAccountLoginParam
     * @return: message
     * @Date 2021/4/14 17:53
     * @throws
     */

    //@ApiOperation用于描述接口方法，作用于方法上
    @ApiOperation(value = "管理员账号密码登陆",notes = "<span style='color:red;'>用来根据管理员账号密码登陆的接口</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 40007,message = "登录成功",response =ManagerAccountLoginParam.class),
            @ApiResponse(code=20002,message = "账号或密码错误"),
            @ApiResponse(code=40000,message = "账号或密码为空")
    })

    @GetMapping("ManagerAccountNameAndPassword")
    public Result getManagerAccountNameAndPassword(@ModelAttribute @ApiParam ManagerAccountLoginParam managerAccountLoginParam){

        log.info("管理员登录开始：参数：{}",managerAccountLoginParam);

        //判断账号和密码是否为空
        if (managerAccountLoginParam.getManagerAccountName()!=null&&managerAccountLoginParam.getManagerAccountPassword()!=null){
            //将前端传入账号密码传入数据层，获取返回值，返回为0 登录成功，1 登录失败
            Integer codess=managerAccountService.getManagerAccount(managerAccountLoginParam);
            if(codess==0){
                log.info("管理员登录结束：参数：{}",codess);
                return new Result(true, StatusCode.LOGIN_SUCCESSFUL, "登录成功");
            }else {
                return new Result(false, StatusCode.LOGINERROR, "账号或密码有误，请重新输入");
            }
        }else {
            return new Result(false, StatusCode.CAN_NOT_BE_EMPTY, "账号或密码为空");
        }
    }

}

